/*
=======================================================================

  BOTS Scientist Research Class Menu

=======================================================================
*/

#include "ui_local.h"
#include "ui_BOTS.h"

typedef struct {
	menuframework_s	menu;

	menutext_s		bodyguard;
	menutext_s		sniper;
	menutext_s		soldier;
	menutext_s		berzerker;
	menutext_s		infiltrator;
	menutext_s		kamikazee;
	menutext_s		nurse;
	menutext_s		cancel;
} researchclassmenu_t;

static researchclassmenu_t	s_researchclassmenu;


/*
=================
BOTS_ScientistResearchClassMenu_Event
callback routine
=================
*/
void BOTS_ScientistResearchClassMenu_Event( void *ptr, int notification ) 
{
	char ls_researchClass[100];
	ls_researchClass[0] = '\0';

	if( notification != QM_ACTIVATED )
		return;

	// any event will kill the menu
	UI_PopMenu();

	switch( ((menucommon_s*)ptr)->id ) 
	{
	case BOTS_CANCEL:
		break;
	case BOTS_BODYGUARD:
		strcpy(ls_researchClass, "bodyguard");
		break;
	case BOTS_SNIPER:
		strcpy(ls_researchClass, "sniper");
		break;
	case BOTS_SOLDIER:
		strcpy(ls_researchClass, "soldier");
		break;
	case BOTS_BERZERKER:
		strcpy(ls_researchClass, "berzerker");
		break;
	case BOTS_INFILTRATOR:
		strcpy(ls_researchClass, "infiltrator");
		break;
	case BOTS_KAMIKAZEE:
		strcpy(ls_researchClass, "kamikazee");
		break;
	case BOTS_NURSE:
		strcpy(ls_researchClass, "nurse");
		break;
		
	// oops - not a valid choice
	default:
		Com_Printf("%i is not a valid choice\n", ((menucommon_s*)ptr)->id);
		break;
	}

	if (ls_researchClass[0] != '\0')
		trap_Cmd_ExecuteText( EXEC_APPEND, va("UI_to_server_classresearch %s\n", ls_researchClass));
}

/*
=================
BOTS_ClassJoinMenu_Init
=================
*/
void BOTS_ScientistResearchClassMenu_Init( void ) 
{
	int					y;
	char				info[MAX_INFO_STRING];
	uiClientState_t		cs;

	int	bodyguard	= 0;
	int	sniper		= 0;
	int	soldier		= 0;
	int	berzerker	= 0;
	int	infiltrator	= 0;
	int	kamikazee	= 0;
	int	nurse		= 0;

	int	bodyguard_level		= 0;
	int	sniper_level		= 0;
	int	soldier_level		= 0;
	int	berzerker_level		= 0;
	int	infiltrator_level	= 0;
	int	kamikazee_level		= 0;
	int	nurse_level			= 0;

	// get the config string and the data it holds
	trap_GetClientState( &cs );
	trap_GetConfigString( CS_BOTS_MENU + cs.clientNum, info, MAX_INFO_STRING );

	bodyguard	= atoi(Info_ValueForKey( info, "bb"));
	sniper		= atoi(Info_ValueForKey( info, "bs"));
	soldier		= atoi(Info_ValueForKey( info, "bd"));
	berzerker	= atoi(Info_ValueForKey( info, "bz"));
	infiltrator	= atoi(Info_ValueForKey( info, "bi"));
	kamikazee	= atoi(Info_ValueForKey( info, "bk"));
	nurse		= atoi(Info_ValueForKey( info, "bn"));

	bodyguard_level		= atoi(Info_ValueForKey( info, "bbx"));
	sniper_level		= atoi(Info_ValueForKey( info, "bsx"));
	soldier_level		= atoi(Info_ValueForKey( info, "bdx"));
	berzerker_level		= atoi(Info_ValueForKey( info, "bzx"));
	infiltrator_level	= atoi(Info_ValueForKey( info, "bix"));
	kamikazee_level		= atoi(Info_ValueForKey( info, "bkx"));
	nurse_level			= atoi(Info_ValueForKey( info, "bnx"));

	memset( &s_researchclassmenu, 0 ,sizeof(researchclassmenu_t) );

	s_researchclassmenu.menu.wrapAround = qtrue;
	s_researchclassmenu.menu.fullscreen = qfalse;

	y = 96;
	s_researchclassmenu.bodyguard.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.bodyguard.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.bodyguard.generic.x			= 320;
	s_researchclassmenu.bodyguard.generic.y			= y;
	s_researchclassmenu.bodyguard.generic.id		= BOTS_BODYGUARD;
	s_researchclassmenu.bodyguard.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.bodyguard.string			= "BODYGUARD";
	s_researchclassmenu.bodyguard.color				= color_bots_menu;
	s_researchclassmenu.bodyguard.style				= UI_CENTER|UI_SMALLFONT;

	if (!bodyguard) {
		s_researchclassmenu.bodyguard.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_researchclassmenu.sniper.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.sniper.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.sniper.generic.x		= 320;
	s_researchclassmenu.sniper.generic.y		= y;
	s_researchclassmenu.sniper.generic.id		= BOTS_SNIPER;
	s_researchclassmenu.sniper.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.sniper.string			= "SNIPER";
	s_researchclassmenu.sniper.color			= color_bots_menu;
	s_researchclassmenu.sniper.style			= UI_CENTER|UI_SMALLFONT;

	if (!sniper) {
		s_researchclassmenu.sniper.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_researchclassmenu.soldier.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.soldier.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.soldier.generic.x			= 320;
	s_researchclassmenu.soldier.generic.y			= y;
	s_researchclassmenu.soldier.generic.id			= BOTS_SOLDIER;
	s_researchclassmenu.soldier.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.soldier.string				= "SOLDIER";
	s_researchclassmenu.soldier.color				= color_bots_menu;
	s_researchclassmenu.soldier.style				= UI_CENTER|UI_SMALLFONT;

	if (!soldier) {
		s_researchclassmenu.soldier.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_researchclassmenu.berzerker.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.berzerker.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.berzerker.generic.x			= 320;
	s_researchclassmenu.berzerker.generic.y			= y;
	s_researchclassmenu.berzerker.generic.id		= BOTS_BERZERKER;
	s_researchclassmenu.berzerker.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.berzerker.string			= "BERZERKER";
	s_researchclassmenu.berzerker.color				= color_bots_menu;
	s_researchclassmenu.berzerker.style				= UI_CENTER|UI_SMALLFONT;

	if (!berzerker) {
		s_researchclassmenu.berzerker.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_researchclassmenu.infiltrator.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.infiltrator.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.infiltrator.generic.x			= 320;
	s_researchclassmenu.infiltrator.generic.y			= y;
	s_researchclassmenu.infiltrator.generic.id			= BOTS_INFILTRATOR;
	s_researchclassmenu.infiltrator.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.infiltrator.string				= "INFILTRATOR";
	s_researchclassmenu.infiltrator.color				= color_bots_menu;
	s_researchclassmenu.infiltrator.style				= UI_CENTER|UI_SMALLFONT;

	if (!infiltrator) {
		s_researchclassmenu.infiltrator.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_researchclassmenu.kamikazee.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.kamikazee.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.kamikazee.generic.x			= 320;
	s_researchclassmenu.kamikazee.generic.y			= y;
	s_researchclassmenu.kamikazee.generic.id		= BOTS_KAMIKAZEE;
	s_researchclassmenu.kamikazee.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.kamikazee.string			= "KAMIKAZEE";
	s_researchclassmenu.kamikazee.color				= color_bots_menu;
	s_researchclassmenu.kamikazee.style				= UI_CENTER|UI_SMALLFONT;

	if (!kamikazee) {
		s_researchclassmenu.kamikazee.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_researchclassmenu.nurse.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.nurse.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.nurse.generic.x			= 320;
	s_researchclassmenu.nurse.generic.y			= y;
	s_researchclassmenu.nurse.generic.id		= BOTS_NURSE;
	s_researchclassmenu.nurse.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.nurse.string			= "NURSE";
	s_researchclassmenu.nurse.color				= color_bots_menu;
	s_researchclassmenu.nurse.style				= UI_CENTER|UI_SMALLFONT;

	if (!nurse) {
		s_researchclassmenu.nurse.generic.flags |= QMF_GRAYED;
	}

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_researchclassmenu.cancel.generic.type		= MTYPE_PTEXT;
	s_researchclassmenu.cancel.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_researchclassmenu.cancel.generic.x		= 320;
	s_researchclassmenu.cancel.generic.y		= y;
	s_researchclassmenu.cancel.generic.id		= BOTS_CANCEL;
	s_researchclassmenu.cancel.generic.callback	= BOTS_ScientistResearchClassMenu_Event; 
	s_researchclassmenu.cancel.string			= "CANCEL";
	s_researchclassmenu.cancel.color			= color_bots_menu;
	s_researchclassmenu.cancel.style			= UI_CENTER|UI_SMALLFONT;

	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.bodyguard );
	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.sniper );
	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.soldier );
	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.berzerker );
	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.infiltrator );
	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.kamikazee );
	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.nurse );
	Menu_AddItem( &s_researchclassmenu.menu, &s_researchclassmenu.cancel );
}

/*
=================
BOTS_ClassJoinMenu_f
=================
*/
void BOTS_ScientistResearchClassMenu_f( void ) {
	// force as top level menu
	uis.menusp = 0;  

	// set menu cursor to a nice location
	uis.cursorx = 319;
	uis.cursory = 80;

	BOTS_ScientistResearchClassMenu_Init();
	UI_PushMenu( &s_researchclassmenu.menu );
}
